import { PagingMessage, YScrollableContainer } from './../../../components/scrollable/y-scrollable-container';
import { Observable } from 'rxjs';
import { GrowlMessageType } from './../../../components/messageBox/growMeaageType';
import { MessageBoxService } from './../../../components/messageBox/messageBoxService';
import { NavigateManage } from './../../../common/navigateManage';
import { Employee } from './../../../models/Employee';
import { EmployeeInfosManage, EmployeInfo, EmployeInfoStatus } from './../../../services/employeesInfoManage';
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { employeesService } from './../../../services/employee';
import * as R from "ramda";

@Component({
    templateUrl: './deliverSetup.component.html',
    styleUrls: ['./deliverSetup.component.scss']
})

export class DeliverComponent implements OnInit, AfterViewInit {
    @ViewChild(YScrollableContainer)
    private yScrollableContainer: YScrollableContainer;
    checkedValuesResult: any;
    private turnsList;
    checkboxValues;
    checkedValues;
    private nextCount;
    private previousCount;
    async ngOnInit() {

    }
    async ngAfterViewInit() {
        const employees = await employeesService.getDishesDistributor();
        const employeeInfos = EmployeeInfosManage.current.getEntities();
        employees.forEach(employee => {
            employee.status = employeeInfos && employeeInfos.find(employeeInfo => employeeInfo.id == employee.id).status;
        })
        this.turnsList = EmployeeInfosManage.current.getTurns();
        this.checkboxValues = employees.map(x => {
            return {
                id: x.id,
                label: x.user.name
            }
        })
        setTimeout(()=>{
            this.yScrollableContainer.childrenChanged();
        },500)
    }

    onChange(checkedValues) {
        this.checkedValuesResult = checkedValues;
    }

    async tabFocusChange(turn) {
        this.checkedValuesResult = await EmployeeInfosManage.current.getEmployeeInfosByTurn(turn).map(x => x.id);
        setTimeout(()=>{
            this.yScrollableContainer.childrenChanged();
        },500)
    }

    async saveOnlineEmployeeInfos() {
        EmployeeInfosManage.current.saveEmployeInfosOnlineByIds(this.checkedValuesResult);
        MessageBoxService.current.Growl(GrowlMessageType.Success, '保存成功');
    }

    pagingInfo: PagingMessage
    pagingMessageChange(event) {
        console.log("2222", event)
        this.pagingInfo = event;
        this.nextCount = this.pagingInfo.nextCount;
        this.previousCount = this.pagingInfo.previousCount;
    }
}